package org.hy.service.group;

import java.util.List;

import org.hy.domain.User;
import org.hy.domain.group.GMember;
import org.hy.domain.group.Group;
import org.hy.persistence.group.GMemberMapper;
import org.hy.util.AppConstant;
import org.hy.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 小组成员服务类的实现类
 * @author xwm
 *
 */
@Service
@Transactional
public class GMemberServiceImpl implements IGMemberService{
	@Autowired
	private GMemberMapper gMemberMapper;

	@Override
	public int addGMember(GMember gMember) {
		if(gMember == null)return AppConstant.FAIL;
		return gMemberMapper.insertGMember(gMember);
	}

	@Override
	public int deleteGMember(int idGmember) {
		return gMemberMapper.deleteGMember(idGmember);
	}

	@Override
	public GMember findGMemberById(int id) {
		return gMemberMapper.findGMemberById(id);
	}

	@Override
	public List<Group> findJoinedGroupByUid(int uid, int page, int size) {
		int offset = Pager.getOffset(page, size);
		return gMemberMapper.findJoinedGroupByUid(uid, offset, size);
	}

	@Override
	public List<User> findRecentlyJoinedGMember(int gid, int page, int size) {
		int offset = Pager.getOffset(page, size);
		return gMemberMapper.findRecentlyJoinedGMember(gid, offset, size);
	}

	@Override
	public int updateGMemberStatus(GMember gMember) {
		if(gMember == null)return AppConstant.FAIL;
		return gMemberMapper.updateGMemberStatus(gMember);
	}

	@Override
	public List<Integer> countGMember(int[] gids) {
		if(gids == null || gids.length == 0) return null;
		return gMemberMapper.countGMember(gids);
	}

	@Override
	public GMember findGMemberByUidAndGid(int uid, int gid) {
		return gMemberMapper.findGMemberByUidAndGid(uid, gid);
	}
	
	
}
